package com.dcsgo.myTankGameServers;

import com.dcsgo.myTankGameServers.common.*;
import com.dcsgo.myTankGameServers.util.MyRandom;

import java.io.FileReader;
import java.io.IOException;
import java.util.*;

/**
 * @author DCSGO
 * @version 1.0
 * 所有坦克管理类
 */
public class TankManager {
    private static HashMap<Integer, PlayerTank> tanks;
    private static final Properties properties = new Properties();

    //在地图上随机生成一个坦克
    public static void produceTank(int key) {
        int panelHeight = Integer.parseInt(properties.getProperty("panelHeight"));
        int panelWidth = Integer.parseInt(properties.getProperty("panelWidth"));
        int x = MyRandom.getRandom(60, panelWidth - 60);
        int y = MyRandom.getRandom(60, panelHeight - 60);
        PlayerTank playerTank = new PlayerTank(x, y,
                Integer.parseInt(properties.getProperty("playerTankSpeed")));
        tanks.put(key, playerTank);
    }

    static {
        try {
            properties.load(new FileReader(MyTankGame.propertiesPath));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static HashMap<Integer, PlayerTank> getTanks() {
        return tanks;
    }

    //销毁坦克
    public static void remove(int key) {
        PlayerTank playerTank = tanks.get(key);
        Vector<Shot> shots = playerTank.shots;
        for (Shot sh : shots) {
            sh.visible = false;
        }
        shots.clear();
        playerTank.isLive = false;
        tanks.remove(key);
    }


}
